package com.doit.doc;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ApisDemo4 {
    public static void main(String[] args) throws IOException {

        //文件中的内容：hello,doit
        FileInputStream fis = new FileInputStream(new File("D:\\test\\a.txt"));
        //每次读取一个字节
        int read = fis.read();
        System.out.println((char) read);//104    h    通过ascii表查到h就是104


        //一次读取一个字节，效率低
        int num = 0;
        while ((num = fis.read()) != -1){
            System.out.print((char) num);//hello,doit
        }


        //长度为1024的字节数组
        byte[] bytes = new byte[1024];
        int n = 0;
        while ((n = fis.read(bytes))!=-1){
            String s = new String(bytes, 0, n);
            System.out.println(s);
        }

        //跳过几个字节再去读
        long skip = fis.skip(5);
        int num1 = 0;
        while ((num1 = fis.read()) != -1){
            System.out.print((char) num1);//,doit
        }


        //关闭资源
        fis.close();


    }
}
